package main.java.com.mkyong.common.action;
 
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
 
public class UserAction extends Action{
 
	private static final Logger logger = Logger.getLogger(UserAction.class);
	
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) 
        throws Exception {
 
		if(logger.isDebugEnabled()){
			logger.debug("Starting started");
		}
		
		DynaActionForm userForm = (DynaActionForm)form;
		
		ActionMessages errors = new ActionMessages();

		//do the form validation in action class
	    if( userForm.get("username") == null || ("".equals(userForm.get("username")))) {
	       errors.add("common.name.err",
             new ActionMessage("error.common.name.required"));
	    }
 
	    saveErrors(request,errors);
	    
	    throw new IOException();
	    
	    /*if(errors.isEmpty()){
	        return mapping.findForward("success");
	    }else{
	        return mapping.findForward("failed");
	    }*/
	   
	    
	    
	}
 
}